//
// Created by HP on 2024/1/25.
//

#ifndef AURORA_ST_AS5047_DRIVER_H
#define AURORA_ST_AS5047_DRIVER_H

#include "common_inc.h"

class AS5047_Driver{




public:
    AS5047_Driver(SPI_HandleTypeDef *spi,GPIO_TypeDef* CS_Porti,uint16_t CS_Pini);


    float as5047_read_angle(bool daec_en);  //dynamic angle error compensation

    float as5047_read_gap();    //位置偏差
    float as5047_read_speed();  //获取速度
    uint8_t as5047_read_speed_update(){return speed_update;};  //获取速度
public:

    void _spi_send(uint16_t addr,uint16_t data);
    uint16_t _spi_read(uint16_t addr);

private:
    void _spi_cs_H();
    void _spi_cs_L();
    void _spi_mode_set();
private:
    SPI_HandleTypeDef *hspi;
    GPIO_TypeDef* CS_Port;
    uint16_t CS_Pin;
    uint8_t  cnt;
    uint8_t  speed_update;
    float    last_angle;

public:
    float    speed_rad;
    float    pos_gap;


};



#endif //AURORA_ST_AS5047_DRIVER_H
